package com.google.code.shardbatis.converter;

import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.insert.Insert;

public class InsertSqlConverter extends AbstractSqlConverter {
	
	@Override
	public String getOriginalTableName(Statement statement) {
		if (!(statement instanceof Insert)) {
			throw new IllegalArgumentException("The argument statement must is instance of Insert.");
		}

		Insert insert = (Insert) statement;

		return insert.getTable().getName();
	}

	@Override
	protected Statement doConvert(Statement statement, String tableName) {
		if (!(statement instanceof Insert)) {
			throw new IllegalArgumentException("The argument statement must is instance of Insert.");
		}

		Insert insert = (Insert) statement;

		insert.getTable().setName(tableName);

		return insert;
	}
	
}